/*******************************************************************************
 * Copyright 2011 @ Kapil Viren Ahuja
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *   http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 ******************************************************************************/
package com.kapilvirenahuja.eamsteps.datareader.excel;

import java.util.ArrayList;
import java.util.List;

import jxl.Cell;

import com.kapilvirenahuja.eamsteps.datareader.IDataCell;
import com.kapilvirenahuja.eamsteps.datareader.IDataRow;

/**
 * @see IDataRow
 *
 */
public class ExcelDataRow implements IDataRow
{
    private final Cell[] row;
    private final String datatable;

    public ExcelDataRow(String datatable, Cell[] row) // NOPMD
    {
        this.datatable = datatable;
        this.row = row;
    }

    /**
     * Returns a cell for a specific cell number.
     *
     */
    public IDataCell getCell(int cellNumber)
    {
        if (cellNumber >= this.row.length || this.row[cellNumber] == null)
        {
            return null;
        }
        else
        {
            return new ExcelDataCell(this.row[cellNumber]);
        }
    }

    public int getCellCount()
    {
        return this.row.length;
    }

    public List<IDataCell> getCells()
    {
        List<IDataCell> cells = new ArrayList<IDataCell>();

        int cellCount = this.getCellCount();
        for (int count = 0; count < cellCount; count++)
        {
            cells.add(this.getCell(count));
        }

        return cells;
    }
    
    public String getTable()
    {
        return this.datatable;
    }
}
